package com.ygl.eurekaclientorder.api.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.spring4all.swagger.EnableSwagger2Doc;
import com.ygl.eurekaclientorder.feign.MemberApiFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author： ygl
 * @date： 2019/01/21
 * @Description：
 */
@Api("订单服务")
@EnableSwagger2Doc
@RestController
public class FeignController {

    @Autowired
    private MemberApiFeign memberApiFeign;

    @ApiOperation("/调用会员")
    @GetMapping("/feignMember")
    public String feignMember(){
        return memberApiFeign.getMember();
    }

    @HystrixCommand(fallbackMethod = "getResp")
    @GetMapping("/feignMemberTimeOut")
    public String feignMemberTimeOut(){
        System.out.println("---订单服务将要调用会员服务－－－");
        return memberApiFeign.getMemberTimeOut();
    }

    private String getResp(){
        return "服务降级";
    }

    @GetMapping("/feignMemberHystrix")
    public String feignMemberHystrix(){
        System.out.println("---订单服务将要调用会员服务－－－");
        return memberApiFeign.getMemberTimeOut();
    }

}
